#include "publics.h"

Publics::Publics(QObject *parent) :
    QObject(parent)
{
}

void Publics::loadQueryToComboBox(QString sql, QString colName, QComboBox *cbo)
{
    QSqlDatabase db = QSqlDatabase::database("odbc_afex");
    QSqlQuery qu = db.exec(sql);
    if (qu.lastError().isValid()) {
        QMessageBox::critical(0, "Error", qu.lastError().text());
        return;
    }
    while (qu.next()) {
        cbo->addItem(qu.record().value(colName).toString());
    }
}

QVariant Publics::getDbValue(QString sql, QString returnCol)
{
    QSqlDatabase db = QSqlDatabase::database("odbc_afex");
    QSqlQuery qu = db.exec(sql);
    if (qu.lastError().isValid()) {
        QMessageBox::critical(0, "Error", qu.lastError().text());
        return 0;
    }

    qu.first();
    return qu.record().value(returnCol);
}
